Prevent zero division by adding a minimum threshold#21
Prevent zero division by adding a minimum threshold#21choROPeNt wants to merge 1 commit intoSkielex:masterfrom
Conversation
Added a maximum function to prevent zero division in calculations.
|
added a tiny little helper to prevent zero division and running into errors |
|
Will take a look as soon as I get time. |
|
Couple of notes and questions:
|
|
Sorry for my late reply, and thanks very much for pulling together your questions. To your comments:
eps = np.nextafter(
np.array(0, dtype=l.dtype),
np.array(1, dtype=l.dtype)
)
l = np.maximum(l, eps)
vec /= lThis guarantees a strictly positive minimum representable value for the corresponding dtype and avoids introducing an arbitrary threshold like 1e-24. Also expierenced vector magnitudes >1 when added a threshold like clipping.
|
|
No problem. Sorry for slow reply too. Been on vacation. While I understand that it's frustrating getting back values like My main arguments against are:
Perhaps I'm missing something here? Is there a reason you can't simply clean the outputs of |
|
One more thing. Is the input |
|
Thanks, that makes sense — and I think I understand your concern more clearly now. I agree that silently applying a cleanup policy inside My main motivation for the pull request is that in structure-tensor applications, near-isotropic regions (e.g., matrix-rich areas in composites) are not invalid input or just floating-point noise. They naturally occur in homogeneous or very low-gradient regions. In these cases the structure tensor itself can approach the zero matrix, since it is computed from local image gradients. As a result, all eigenvalues can become very small and the eigenvector direction becomes ill-defined, so normalization can hit zero or near-zero magnitudes. From my perspective this feels closer to handling an algorithmic degeneracy of the structure tensor rather than purely post-hoc output cleaning. Currently I am working with |
Yes, I see that. The question is what behavior we expect of the functions, i.e., what is "correct" behavior and what's considered valid input and output. Right now we have two parts:
The current train of thoughts go something likes this: Any volume of numbers values should be valid input for We could change
If you actually have structure in all regions of the data, I think |
|
@choROPeNt as of now, I'm not in favor of clipping values. I really appreciate your input though. I think the best approach is usually to use In any case, it is probably a good idea to very/clean output as needed. I prefer to leave that to the caller, as they know best how to handle numerical instability in their data. |
Added a maximum function to prevent zero division in calculations.